<?php
/** Zend_Controller_Action */ 
require_once ROOT_PATH . '/library/Soooner/Controller/Action.php';
class RtreportController extends Soooner_Controller_Action
{
	private $_userid;
	private $_modelRtreport;
    public function init()
    {
        /* Initialize action controller here */
    	$this->initDzTemplate();
    	$this->_modelRtreport = new Model_Tables_Rtreport();
    }
    public function indexliveAction()
    {
		include $this->_dzTemplate->getFile( 'rtreport.live.html' );
    }
	public function indexvodAction()
    {
		include $this->_dzTemplate->getFile( 'rtreport.vod.html' );
    }
	public function indexdeviceAction()
    {
		include $this->_dzTemplate->getFile( 'rtreport.device.html' );
    }
    /**
     * 直播实时报表数据生成
     * /rtreport/live/dsname/online/
     * type:online/cpu/disk/mem/netcard/
     */
    public function liveAction()
    {
    	$result = "";
    	$dsname = $this->_getParam('dsname');
    	$type = $this->_getParam('type');
    	$start = $this->_getParam('start');
    	$end = $this->_getParam('end');
    	$data = $this->_modelRtreport->getDeviceInfoList($type,$start,$end);
    	switch ($dsname)
    	{
    		case "online" : 
    			foreach($data as $row){
    				$result .=  $row['dci_time']. "," . $row['dci_live_online'] . ";";//$row['dci_time']
    			}
    			break;
    		default :    			
    			break;
    	}
    	$result = rtrim($result, ";");
    	echo $result;exit;
    }
	/**
     * 点播实时报表数据生成
     * /rtreport/vod/dsname/online/
     * type:online/cpu/disk/mem/netcard/
     */
    public function vodAction()
    {
    	$result = "";
    	$dsname = $this->_getParam('dsname');
    	$type = $this->_getParam('type');
    	$start = $this->_getParam('start');
    	$end = $this->_getParam('end');
    	$data = $this->_modelRtreport->getDeviceInfoList($type,$start,$end);
    	switch ($dsname)
    	{
    		case "online" : 
    			foreach($data as $row){
    				$result .=  $row['dci_time']. "," . $row['dci_vod_online'] . ";";//$row['dci_time']
    			}
    			break;
    		default :    			
    			break;
    	}
    	$result = rtrim($result, ";");
    	echo $result;exit;
    }
    /**
     * 读取设备信息
     * @param $type
     * @return unknown_type
     */
    public function deviceAction()
    {
    	$result = "";
    	$dsname = $this->_getParam('dsname');
    	$type = $this->_getParam('type');
    	$start = $this->_getParam('start');
    	$end = $this->_getParam('end');
    	$data = $this->_modelRtreport->getDeviceInfoList($type,$start,$end);
    	switch ($dsname)
    	{    		
    		case "cpu":
    			foreach($data as $row){
    				$result .=  $row['dci_time']. "," . $row['dci_cpu'] . ";";//$row['dci_time']
    			}
    			break;
    		case "disk":
    			foreach($data as $row){
    				$result .= $row['dci_time'] . "," . $row['dci_diskfree'] . ";";
    			}
    			break;
    		case "mem":
    			foreach($data as $row){
    				$result .= $row['dci_time'] . "," . $row['dci_mem'] . ";";
    			}
    			break;
    		case "netcard":
    			foreach($data as $row){
    				$result .= $row['dci_time'] . "," . $row['dci_net'] . ";";
    			}
    			break;
    	}
    	$result = rtrim($result, ";");
    	echo $result;exit;
    }
}

